home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Extensions… / Extension Shell multi-seg ƒ / Extension.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-14  |  5.9 KB  |  217 lines  |  [TEXT/MPS ]

  1. /*________________________________________________________
  2.  
  3.     File: Extension.c
  4.  
  5.     C code for a printing extension.
  6.  
  7.     Dave Hersey
  8.     Apple Developer Technical Support
  9.  
  10.     12/01/92 - dmh - Created.
  11.      4/26/93 - dmh - Updated to use recommended approach
  12.                       to global data initialization.
  13.      9/05/93 - dmh - Updated for b2.
  14.                     - Fixed minor problem with highlighting
  15.                      of editText panel items.
  16.                    - Switched to Exception.h assertion stuff
  17.                      for error checking.
  18.     12/18/93 - dmh - Updated for b3.
  19.      3/22/94 - dmh - Updated for b4.
  20.      6/10/94 - dmh - Added GXPRINTINGDISPATCH examples.
  21.      6/14/96 - cn  - Updated to support Universal Interfaces 2.1.
  22.  
  23.     (Note: all functions are in the Mark menu.)
  24.     
  25. __________________________________________________________*/
  26.  
  27. #include "Extension.h"
  28.  
  29.  
  30. /*******************************************************************
  31.     InitGlobalData is used to initialize any global data we need to
  32.     in our initialize message override.  It's critical that you do
  33.     things this way, rather than access the data in the same scope
  34.     that you call NewMessageGlobals.  Otherwise, some compilers
  35.     will give you code that references an invalid A5 world.
  36.  
  37. ********************************************************************/
  38.  
  39. OSErr InitGlobalData()
  40. {
  41. // Initialize any global data here.
  42.     
  43.     return noErr;
  44. }
  45.  
  46.  
  47. /*******************************************************************
  48.     NewInitialize is our override for the GXInitialize message.  In
  49.     here, you shouldn't initialize anything directly-- call
  50.     InitGlobalData for that.  Once you create the A5 world with
  51.     NewMessageGlobals, you can access your global data just like
  52.     you were an application.  Whenever you're called, your global
  53.     data will be valid.
  54.     
  55. ********************************************************************/
  56.  
  57. OSErr NewInitialize()
  58. {
  59.     OSErr    err;
  60.  
  61. // Create an A5 world, and initialize our global data.
  62.  
  63.     err = NewMessageGlobals(A5Size(), A5Init);
  64.     
  65.     if (!err) err = InitGlobalData();
  66.     
  67.     return err;
  68. }
  69.  
  70.  
  71. /*******************************************************************
  72.     NewShutDown is our override for the GXShutDown message.  We
  73.     simply throw away our A5 world which we created in our
  74.     GXInitialize message override, NewInitialize.
  75.     
  76. ********************************************************************/
  77.  
  78. OSErr NewShutDown()
  79. {
  80.     DisposeMessageGlobals();
  81.     return noErr;
  82. }
  83.  
  84.  
  85. /*******************************************************************
  86.     NewSpoolPage is our override for the GXSpoolPage message.  We
  87.     check to see if we're enabled, and if so, give a SysBeep before
  88.     forwarding.
  89.     
  90. ********************************************************************/
  91.  
  92. OSErr NewSpoolPage(gxSpoolFile spFile, gxFormat aFormat, gxShape pgShape)
  93. {
  94.     OSErr                    err;
  95.     ExtensionCollection        extCollect;
  96.     
  97. // Try to retrieve our collection item.  If we can't find it, we'll
  98. // act as if the user had us turned off or on (as determined by
  99. // kDefaultSetting).
  100.  
  101.     err = GetJobCollectionItem(&extCollect, nil, kExtensionCollectionType,
  102.                                gxPrintingTagID);
  103.  
  104.     if (err)
  105.     {
  106.         extCollect.extTurnedOn = kDefaultSetting;
  107.         err = noErr;
  108.     }
  109.  
  110.  
  111. // If we're turned on, beep so we know we've been here, then forward
  112. // this message down the chain.
  113.  
  114.     if (extCollect.extTurnedOn)
  115.         SysBeep(3);
  116.     
  117.     err = Forward_GXSpoolPage(spFile, aFormat, pgShape);
  118.  
  119.     return err;
  120. }
  121.  
  122.  
  123. /*******************************************************************
  124.     NewJobPrintDialog is our override for GXJobPrintDialog.  All we
  125.     do is set up our panel and then forward the message.
  126.     
  127. ********************************************************************/
  128.  
  129. OSErr NewJobPrintDialog(gxDialogResult *dlogResult)
  130. {
  131.     OSErr    err;
  132.  
  133.     err = SetUpPrintPanel();
  134.  
  135.     if (!err)
  136.         err = Forward_GXJobPrintDialog(dlogResult);
  137.     
  138.     return err;
  139. }
  140.  
  141.  
  142. /*******************************************************************
  143.     NewHandlePanelEvent is our override for GXHandlePanelEvent. If
  144.     the event is one of ours, we handle it.  Otherwise, we just
  145.     forward it down the chain.
  146.     
  147. ********************************************************************/
  148.  
  149. OSErr NewHandlePanelEvent(gxPanelInfoRecord *panelInfo)
  150. {
  151.     OSErr            err = noErr;
  152.     GrafPtr            oldPort;
  153.     DialogPtr        pDlg;
  154.  
  155. // Get a pointer to the dialog, save our current grafPort,
  156. // and set us to the dialog's port.
  157.  
  158.     pDlg = panelInfo->pDlg;
  159.     GetPort(&oldPort);
  160.     SetPort(pDlg);
  161.  
  162.     switch (panelInfo->panelEvt)    // Handle any of these events as need be.
  163.     {
  164.         case gxPanelOpenEvt:                // Initialize and draw.
  165.             break;
  166.         case gxPanelCloseEvt:                // Your panel is going away (panel switch,
  167.             break;                            // confirm or cancel).
  168.  
  169.         case gxPanelHitEvt:                    // There's a hit in your panel.
  170.             break;
  171.         case gxPanelFilterEvt:                // This is called to filter every event.
  172.             break;
  173.         case gxPanelCancelEvt:                // The user has cancelled the dialog.
  174.             break;
  175.         case gxPanelConfirmEvt:                // The user has confirmed the dialog.
  176.             break;
  177.         case gxPanelUserWillConfirmEvt:        // user has selected confirm, time to
  178.             break;                            // parse your panel interdependencies.
  179.                                         
  180.         case gxPanelDialogEvt:                // Event to be handled by dialoghandler
  181.             break;                            // (you get to see all events).
  182.  
  183.         case gxPanelOtherEvt:                // osEvts, etc.
  184.             break;
  185.  
  186. // If our panel is activating/deactivating or if the focus (which
  187. // section of the dialog is active) has changed we need to activate
  188. // our editText fields appropriately.
  189.  
  190.         case gxPanelActivateEvt:            // The dialog window has just become active.
  191.         case gxPanelDeactivateEvt:            // The dialog window is becoming inactive.
  192.         case gxPanelIconFocusEvt:            // The user is moving to the icon list.
  193.         case gxPanelPanelFocusEvt:            // The user is moving to the panel.
  194.  
  195. /*  Here's what you would do if you had an editText field at DITL item #5:
  196.  
  197. #define d_edText    5
  198.  
  199.             if ((((DialogPeek) pDlg)->editField +1) == (panelInfo->itemCount +d_edText))
  200.             {
  201.                 if (panelInfo->panelEvt == gxPanelPanelFocusEvt)
  202.                     TEActivate(((DialogPeek) pDlg)->textH);
  203.                 else
  204.                     TEDeactivate(((DialogPeek) pDlg)->textH);
  205.             }
  206. */
  207.             break;
  208.     }
  209.  
  210. // Restore the original port as we leave.
  211.  
  212.     SetPort(oldPort);
  213.     return err;
  214. }
  215.  
  216.  
  217.